---
title: Infra Resources
sidebarTitle: Resources
---

The `infra` directory in a codebase contains the resources that are created/deleted using `ag infra up`/`ag infra down`.

Any `.py` file in the `infra` containing a `DockerResources`, `AwsResources` or `K8sResources` object can be used to define the workspace resources.

To add your own resources, just create a python file, define resources and add them to a `DockerResources`, `AwsResources` or `K8sResources` object.

## Example

### DockerResources

```python infra/dev_resources.py
from agno.docker.app.fastapi import FastApi
from agno.docker.app.postgres import PgVectorDb
from agno.docker.app.streamlit import Streamlit
from agno.docker.resources import DockerResources

#
# -*- Resources for the Development Environment
#

# -*- Dev image
dev_image = DockerImage(
    ...
)

# -*- Dev database running on port 5432:5432
dev_db = PgVectorDb(
    ...
)

# -*- Streamlit running on port 8501:8501
dev_streamlit = Streamlit(
    ...
)

# -*- FastAPI running on port 8000:8000
dev_fastapi = FastApi(
    ...
)

# -*- Dev DockerResources
dev_docker_resources = DockerResources(
    env=ws_settings.dev_env,
    network=ws_settings.ws_name,
    apps=[dev_db, dev_streamlit, dev_fastapi, dev_jupyter_app],
)
```

### AwsResources

```python infra/prd_resources.py
from agno.aws.app.fastapi import FastApi
from agno.aws.app.streamlit import Streamlit
from agno.aws.resources import AwsResources
from agno.aws.resource.ecs import EcsCluster
from agno.aws.resource.ec2 import SecurityGroup, InboundRule
from agno.aws.resource.rds import DbInstance, DbSubnetGroup
from agno.aws.resource.reference import AwsReference
from agno.aws.resource.s3 import S3Bucket
from agno.aws.resource.secret import SecretsManager
from agno.docker.resources import DockerResources
from agno.docker.resource.image import DockerImage

#
# -*- Resources for the Production Environment
#

# -*- Production image
prd_image = DockerImage(
    ...
)

# -*- S3 bucket for production data
prd_bucket = S3Bucket(
    ...
)

# -*- Secrets for production application
prd_secret = SecretsManager(
    ...
)
# -*- Secrets for production database
prd_db_secret = SecretsManager(
    ...
)

# -*- Security Group for the load balancer
prd_lb_sg = SecurityGroup(
    ...
)
# -*- Security Group for the application
prd_sg = SecurityGroup(
    ...
)
# -*- Security Group for the database
prd_db_port = 5432
prd_db_sg = SecurityGroup(
    ...
)

# -*- RDS Database Subnet Group
prd_db_subnet_group = DbSubnetGroup(
    ...
)

# -*- RDS Database Instance
prd_db = DbInstance(
    ...
)

# -*- Streamlit running on ECS
prd_streamlit = Streamlit(
    ...
)

# -*- FastAPI running on ECS
prd_fastapi = FastApi(
    ...
)

# -*- Production DockerResources
prd_docker_resources = DockerResources(
    env=infra_settings.prd_env,
    network=infra_settings.infra_name,
    resources=[prd_image],
)

# -*- Production AwsResources
prd_aws_resources = AwsResources(
    env=infra_settings.prd_env,
    apps=[prd_streamlit, prd_fastapi],
    resources=[prd_lb_sg, prd_sg, prd_db_sg, prd_secret, prd_db_secret, prd_db_subnet_group, prd_db, prd_bucket],
)
```
